package leetcode;

public class ReverseDigitsOfInteger {
	public static int reverse(int x) {
		if(x==0){
			return 0;
		}
		int res = 0;
		while(x!=0){
			int curNum = x%10;
			res = res*10 +curNum;
			if(res  > Integer.MAX_VALUE/10- x/10){
				return 0;
			}
			x=x/10;
		}
		
		return res;
		
	}
	public static void main(String[] args) {
			System.out.println(reverse(1000000003));
	}
}
